package com.appspot.redalert;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

public class Main extends Activity {
	private static final int SPLASH_SCREEN_DIALOG = 20;
	private SplashScreen splash_screen;
	private Callbacks callback;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = new Intent(this, LocalService.class);
        startService(intent); 
        
        setContentView(R.layout.main);
        callback = new Callbacks();
        showDialog(SPLASH_SCREEN_DIALOG);
    }

	private static final int MENU_SETTINGS = Menu.FIRST;

	// Invoked the first time the 'menu' button is pressed.
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		Log.d("redalert", "Menu called");
		menu.add(0, MENU_SETTINGS, MENU_SETTINGS, "Settings").setShortcut('1',
				's').setIcon(R.drawable.settings_icon);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case MENU_SETTINGS:
			// Start the vibration
			Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
			long pattern[] = { 0, 100, 200, 300, 600 };
			vibrator.vibrate(pattern, -1);
			return true; // We caught our event,
			// stop the processing here: don't want to propagate
			// in the system.
		}
		// We don't know anything about this event, pass it along.
		return super.onOptionsItemSelected(item);
	}
    @Override
    protected Dialog onCreateDialog(int id) {
        if (id == SPLASH_SCREEN_DIALOG) {
            splash_screen = new SplashScreen(this, callback);
            //splash_screen.setOnCancelListener(this);
            return splash_screen;
        }
        return null;
    }

}